﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace Palsta.Core
{
    public class DataInfoFactory
    {
        public static DataInfo CreateInstance(XmlNode node)
        {
            DataType type;
            bool nillable = false;
            if (node.Attributes["type"] == null) return null;
            String typeValue = node.Attributes["type"].Value.ToLower();
            if (node.Attributes["nillable"] != null && node.Attributes["nillable"].Value.ToLower().Trim() == "true") 
            {
                nillable = true;
            }
            switch (typeValue)
            {
                case "xsd:boolean":
                    type = DataType.Boolean;
                    break;
                case "xsd:string":
                    type = DataType.String;
                    break;
                default:
                    type = DataType.Boolean;
                    break;
            }
            return new DataInfo("my:" + node.Attributes["name"].Value, nillable, type);
        }
    }
}
